package com.ewanghuiju.app.ui.pintuan.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.model.bean.response.PintuanGoodsSpecsResponBean;

import androidx.core.content.ContextCompat;

/**
 * @author sj  qq:751943509
 * @class 流式布局  规格选择 adapter
 * @time 2020/2/20
 */
public class FlexboxAdapter extends BaseQuickAdapter<PintuanGoodsSpecsResponBean, BaseViewHolder> {

    private int mType;

    public FlexboxAdapter(int layoutResId, int type) {
        super(layoutResId);
        this.mType = type;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    protected void convert(BaseViewHolder helper, PintuanGoodsSpecsResponBean item) {

        TextView tvFlexbox = helper.getView(R.id.tv_flexbox_item);
        if (mType == 1) {
            if (TextUtils.isEmpty(item.getName_value())) {
                tvFlexbox.setVisibility(View.GONE);
            } else {
                tvFlexbox.setVisibility(View.VISIBLE);
                tvFlexbox.setText(item.getName_value());
            }
        } else {
            if (TextUtils.isEmpty(item.getValue())) {
                tvFlexbox.setVisibility(View.GONE);
            } else {
                tvFlexbox.setVisibility(View.VISIBLE);
                tvFlexbox.setText(item.getValue());
            }
        }
        if (item.isSelected()) {
            tvFlexbox.setBackgroundResource(R.drawable.corner_flowlayout_selected_50);
            tvFlexbox.setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimary));
        } else {
            tvFlexbox.setBackgroundResource(R.drawable.corner_f2f2f2_50);
            tvFlexbox.setTextColor(ContextCompat.getColor(mContext, R.color.color_333));
        }

        tvFlexbox.setSelected(item.isSelected());
    }
}
